package api_servers
{
	import UIFree.uif_app;
	
	import flash.net.URLRequest;
	import flash.net.URLRequestHeader;
	import flash.net.URLRequestMethod;
	import flash.utils.ByteArray;

	public class api_oneMyserver extends api_myserver {
		public var _model_name		: String;
		public var _upload_url		: String;
		
		public function api_oneMyserver(api_url:String, a_api_id:String, a_secret:String, 
										a_model_name: String, a_upload_url: String) {
			super(uif_app.instance(), api_url, a_api_id, a_secret);
			_model_name = a_model_name;
			_upload_url = a_upload_url;
		}
		
		public function oneQuery(method: String, str_params: String='', _handle: Function=null, a_cache: Boolean = false, a_url: String = ''): void {
			var params: Array = [
				{pn:'querycount', pv: 1},
				{pn:'query1', pv: _model_name + ';' + method + ';' + str_params}
			];
			
			jsrHelper(params, _handle, method, a_cache, a_url);
		}
		
		public function removeImage(fileName: String): void {
			oneQuery('removeImage', fileName, null, false, _upload_url);
		}
		
		public function collectorImage(path: String, JPGData: ByteArray, _handle: Function=null, uploadServer: String = ''): void {
			var _params: Array = [
				{pn:'querycount', pv: 1},
				{pn:'query1', pv: _model_name + ';uploadJPGImage;' + 
					sroot.externalServer.viewer_id + ';' + path
				}
			];
			
			if (!uploadServer) uploadServer = _upload_url;
			
			var header: URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
			var request: URLRequest = createRequest(_params, uploadServer, URLRequestMethod.GET);
			request.method = URLRequestMethod.POST;
			request.requestHeaders.push(header);
			request.data 	= JPGData;
			
			jsrHelper(_params, _handle, 'collectorImage', false, '', request);
		}
	}
}